In many situations it is required to transform software objects from one structure to another. The term object may refer to an actual software structure which has allocated memory space and resides in the memory of the computer, or to a description of an object, which is stored in a persistent storage, such as a file or a database residing on a storage device.
Object transformation refers to situations in which content is received in the form of a first representation, and a second representation is to be constructed using some or all of the content. The situations include but are not limited to upgrading a first object crated by or associated with an early version of a product, into a second object created by or associated with a more advanced version; deriving from a relatively large object a lighter representation to be transferred over the communication channel; transforming database structures, or the like.
In some applications, one or more objects to be transformed are hierarchical objects. A hierarchical object is an object in which some fields or members may be simple attributes that may be assigned a value, while at least one member is a list or another container, comprising further attributes, lists or containers.
Some known methods for object transformation include XSLT, which transforms between XML structures. Aside from the hierarchy handling, XSLT is in essence similar to “sed”, “awk” or other text manipulation systems, since XSLT is unaware of the internal structures of the underlying objects. Therefore, among other deficiencies, XSLT does not eliminate fields of the old object which are not required in the new object, does not perform simple conversions, and others.
Thus, a programmer using XSLT still has to manually provide all the specific field and member transformations, and little work is performed automatically.
An approach similar to XSLT relates to transforming an object of a first type to an object of a second type by following a change list. However, this approach requires an ordered change list, and is thus suitable for two objects, wherein the second of which was derived by a chain of changes from the first one.
Casting operators, which are common in object-oriented programming languages are operative only in casting objects from a derived class into objects of a base class or vice versa, and are not applicable in transformations between alien objects.
There is thus a need in the art for a method and system for transforming objects in general, and hierarchical objects in particular, from a first representation into a second representation. The method and system should automatically transform all possible fields or members of the objects. For those fields or members that require business logic or other operations for conversion, the method and system should provide easy access for a user to complete the transformation.